<template>
    <div>
        <detail-banner
            :sightName="sightName"
            :bannerImg="bannerImg"
            :bannerImgs="gallaryImg"
            ></detail-banner>
        <detail-header></detail-header>
        <!-- 为了显示jheader的效果，添加div增长页面长度 -->
        <div class="content">
            <detail-content
                :infos="infos"
                :tickets="tickets"
            ></detail-content>
            <!-- <detail-list :list="list"></detail-list> -->
        </div>
    </div>
</template>

<script>
import DetailBanner from './components/Banner.vue'
import DetailHeader from './components/Header.vue'
import DetailList from './components/List.vue'
import DetailContent from './components/Content.vue'
import axios from 'axios'

export default {
    name: 'Detail',
    components: {
        // 局部组件注册
        DetailBanner,
        DetailHeader,
        DetailList,
        DetailContent
    },
    data () {
        return {
            sightName: '',
            bannerImg: '',
            gallaryImg: [],
            list: [],
            infos: [],
            tickets: []
        }
    },
    methods: {
        getDetailInfo () {
            // 动态路由中的id数据，拼接比较麻烦，可以用法2
            // axios.get('/api/detail.json?id=' + this.$router.params.id)
            axios.get('/api/detail.json', {
                params: {
                    // 注意这里是route而不是router
                    id: this.$route.params.id
                }
            }).then(this.handleGetDataSucc)
        },
        handleGetDataSucc (res) {
            res = res.data
            if (res.ret && res.data) {
                const data = res.data
                this.sightName = data.sightName
                this.bannerImg = data.bannerImg
                this.gallaryImg = data.gallaryImgs
                this.list = data.categoryList
                this.infos = data.infos
                this.tickets = data.tickets
            }
        }
    },
    mounted () {
        // 当页面不缓存时，每次进入页面mounted都会执行
        this.getDetailInfo()
    }
}
</script>

<style lang="stylus" scoped>
    .content
        height: 50rem
        border-radius: .1rem .1rem 0 0
</style>
